﻿@using PicStore.Model
@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<script type="text/javascript" src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/RequestModel.js?a=2" type="text/javascript"></script>

<div class="form-search">
    <fieldset>
        <legend data-bind="text: title"></legend>
        @{
            if (ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.Admin.ToString().ToLower())
            {
                <span class="pull-left">
                    <!--ko foreach: searchCriteria-->
                    <label class="control-label" data-bind="text: displayText"></label>
                    <input class="search-query input-medium" data-bind="value: value" />
                    <!--/ko-->                    
                    <a href="#" data-bind = "click: search" class="btn btn-primary">Search</a>
                    <a href="#" data-bind = "click: reset" class="btn">reset</a>
                </span>
                <span class="pull-right">
                    <a href="~/Apply/Add" class="btn btn-primary">Create New Download Request</a>
                </span>
            }
            else if (ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.Manager.ToString().ToLower())
            {
                <span class="pull-left">
                    <!--ko foreach: searchCriteria-->
                    <label class="control-label" data-bind="text: displayText"></label>
                    <input class="search-query input-medium" data-bind="value: value" />
                    <!--/ko-->                    
                    <a href="#" data-bind = "click: search" class="btn btn-primary">Search</a>
                    <a href="#" data-bind = "click: reset" class="btn">reset</a>
                </span>
            }
            else if (ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.Viewer.ToString().ToLower() ||
                ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.HighViewer.ToString().ToLower())
            {
                <span class="pull-left">
                    <a href="~/Apply/Add" class="btn btn-primary">Create New Download Request</a>
                </span>
            }
        }
    </fieldset>
</div>
<br/><label id="labelError" class="error"></label>
<table class="table table-striped table-bordered table-condensed">
    <thead>
        <tr data-bind="foreach: headers">
            <th data-bind="style: {width: width}" >
                <a href="#" data-bind="text: displayText, click: $root.sort"></a>
                <i class="icon-circle-arrow-up" data-bind="visible: value == $root.orderBy() && canOrder == 'true' && $root.isAsc()"> </i>
                <i class="icon-circle-arrow-down" data-bind="visible: value == $root.orderBy() && canOrder == 'true' && !$root.isAsc()" ></i> 
            </th>
        </tr>
    </thead>
    <tbody data-bind="foreach: recordSet">
        <tr>
            @RenderBody() 
            <td>
                @{
                    if (ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.Admin.ToString().ToLower())
                    {
                        <button data-bind="click: $root.onDataApproving, visible: ShowApproveButton ">Approve</button>
                        <button data-bind="click: $root.onDataDownload, visible: ShowDownloadButton ">Dowload</button>
                        <br/>
                        <button data-bind="click: $root.onDataRejecting, visible: Status == '@RequestStatus.未处理.ToString()'">Reject</button>
                    }
                    else if (ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.Manager.ToString().ToLower())
                    {
                        <button data-bind="click: $root.onDataDownload, visible: ShowDownloadButton ">Dowload</button>
                    }
                    else if (ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.Viewer.ToString().ToLower() ||
                        ViewData["RoleName"].ToString().ToLower() == PicStore.Model.RoleEnum.HighViewer.ToString().ToLower())
                    {
                        <button data-bind="click: $root.onDataDeleting, visible: Status == '@RequestStatus.未处理.ToString()'" >Delete</button>
                    }
                }
                
            </td>
        </tr>
    </tbody>
</table>
 
<div class="pagination pagination-centered">
    <ul data-bind="foreach: pageNumbers">
        <li data-bind="css: {selected: $index() == $root.pageIndex() - 1}">
            <a href="#" data-bind="text: $data, click: $root.turnPage" ></a>
        </li>
    </ul>
</div>
<div class="modal fade hide" id="dialog" data-backdrop ="static" data-bind="html:dialogContent"></div>
@RenderSection("Script")
